-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: Update config diff check method to handle nested arrays #7579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
src/plot_api/helpers.js
Outdated
return false; | ||
}; | ||
|
||
const AX_LETTERS = ['x', 'y', 'z']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put at top of file perhaps? I would normally expect constants not inside a function to be defined at the top of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do.
src/plot_api/helpers.js
Outdated
* @param {Object|Array} oldCollection: Old version of collection to compare | ||
* @param {Object|Array} newCollection: New version of collection to compare | ||
*/ | ||
const hasCollectionChanged = (oldCollection, newCollection) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a nit, but I would expect this function to be called something slightly more general like areObjectsEqual()
since the function itself doesn't care whether oldCollection
and newCollection
are versions of the same object or not; that's a matter of how the function is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to be generic with the term "collection" since you could be passing in an object or an array, but we could go further as you suggest. Would areCollectionsEqual
be acceptable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, areCollectionsEqual
(or maybe collectionsAreEqual
?) sounds good to me 👍
Actually, one related question — what is the reason for ignoring keys starting with an underscore? Is that due to a JavaScript implementation detail, or a Plotly.js one? Maybe that should be captured in the function name (since it's a very particular definition of equality)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a plotly.js detail, but it's also a JavaScript convention. Variables that start with underscore are labeled as such because they are meant to be used internally by the library. So, you wouldn't see a user changing those values, hence they can be ignored.
src/plot_api/helpers.js
Outdated
if (Object.keys(oldCollection).length !== Object.keys(newCollection).length) return true; | ||
|
||
for (const k in oldCollection) { | ||
if (k.startsWith('_')) return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems wrong, am I missing something? Is it supposed to be if (k.startsWith('_')) continue;
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, looking closely this whole loop is problematic; it should only ever return true
from within the loop. Line 535 will return false
sometimes and short-circuit the whole loop if hasCollectionChanged(oldVal, newVal)
returns false
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I did a poor job of converting this loop from it's previous iteration. I updated it to only return when true
.
@camdecoster Infinite loop is resolved, but I am not able to update the modebar buttons successfully by calling This is the line I am running in the browser console: Plotly.react(gd, gd.data, gd.layout, { modeBarButtons: [['zoom2d', 'pan2d'], ['autoScale2d', 'resetScale2d']] }); I would expect to see new buttons show up in the modebar but I see nothing. I am also seeing that |
Also have you been able to learn anything about the intentions behind this test? Unclear whether it was deliberately forbidden for a philosophical reason, or just because it was complicated to implement. |
I've only looked at it to understand why it was failing. In this case, it was because of the bad loop conversion. I'll see if I can understand it a bit better and report back. |
I ask because the wording of the test case ("should not try to transition when the config has changed") seems to directly oppose the functionality you've added (making sure a transition happens during |
Okay, so config changes shouldn't be animated per this comment. The second call to So, the test is there to make sure no transitions happen when a config change occurs. This might actually add a new feature that didn't exist before the changes to |
This was a consequence of the loop logic error. I tried it after the fix and it worked. Could you try again with the latest changes? |
Description
Update config diff check to handle nested arrays.
Closes #7572.
Changes
Testing
react
before you do to avoid crashing your browser/computerreact
from the browser DevTools console with the following command:Notes
react
once and that was it. The new code can make a call toreact
recursively, which is triggered by the above example.modeBarButtons
config option because that's the only one that takes a nested array as a valueTODO